home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000085_icon-group-sender _Mon Apr 15 09:14:19 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 15 Apr 1996 12:27:19 MST
  2. Date: Mon, 15 Apr 1996 09:14:19 -0700
  3. From: kwalker@orville.premenos.com (Ken Walker)
  4. Message-Id: <199604151614.JAA23070@varda.premenos.com>
  5. To: icon-group@cs.arizona.edu
  6. Subject: Re: random numbers...
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=us-ascii
  9. Content-Transfer-Encoding: 7bit
  10. Content-Md5: LpZpYRJRiHqugYwp9aw+jg==
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: O
  13.  
  14. > Date: 15 Apr 96  09:27:09 BST
  15. > From: R J Hare <rjhare@tattoo.ed.ac.uk>
  16. > I'm writing a graphics program which requires that I perturb my x and
  17. > y values randomly by -1|0|1 before plotting the object at the new x and y.
  18. > There seem to be 2 obvious ways of doing this:
  19. > x := x-2+?3
  20. > y := y-2+?3
  21. > or:
  22. > x := x+?[-1,0,1]
  23. > y := y+?[-1,0,1]
  24. > Which is 'best' (quicker, easier to read, etc.)?
  25.  
  26. I find the second easiest to read, but it has the disadvantage of constructing
  27. lists every time it is executed. If you are interested in effeciency, you
  28. might want to precompute the perturbations:
  29.  
  30. procedure foo()
  31.     static perturbations
  32.  
  33.     initial perturbations := [-1, 0, 1]
  34.  
  35.     ...
  36.     
  37.     x := x + ?perturbations
  38.     y := y + ?perturbations
  39.     
  40.     ...
  41.    
  42.   end
  43.   
  44. Even with this modification, it is likely to run a little slower than
  45. the first method, but the difference may not be significant for your
  46. application.
  47.  
  48. Ken Walker, kwalker@premenos.com
  49. Premenos Coporation, Concord, Ca. 94520
  50.  
  51.  
  52.